<?php
namespace app\api\controller;
use app\common\controller\IndexBase;
use think\facade\Request;
use think\facade\Db;
use think\facade\Cache;
use think\facade\Session;

use app\user\model\UserAuthRule;
use app\common\model\User;
use app\user\model\Notice;
use app\user\model\Customer;
use app\user\model\CustomerTrack;
use app\user\model\CustomerOrder;

class Index extends IndexBase
{
    protected function _initialize()
    {
        parent::_initialize();
        
    }
    //首页
    public function home()
    {
        //基本信息
        $data['notice'] = Notice::where('user_id', UserId())->where('status','0')->count();
        $data['customer'] = Customer::where('user_id', UserId())->whereMonth('create_time')->count();
        $data['track'] = CustomerTrack::where('user_id', UserId())->whereMonth('create_time')->count();
        $data['order'] = CustomerOrder::where('user_id', UserId())->whereMonth('create_time')->sum('price');
        //最新
        $customer = Customer::where('user_id', UserId())->order('create_time desc,id desc')->limit(5)->select();
        $track = CustomerTrack::where('user_id', UserId())->order('create_time desc,id desc')->limit(5)->select();
        $order = CustomerOrder::where('user_id', UserId())->order('create_time desc,id desc')->limit(5)->select();
        
        $this->result([
            'data'=>$data,
            'customer' => $customer,
            'track' => $track,
            'order' => $order,
        ]);
    }
    
    
    
    
}
